package model

import (
	"auth/model/entity"
)

type AuthorityCreateRequest struct {
	AuthorityId int64 `json:"authority_id" binding:"required"`

	ParentId int64 `json:"parent_id" default:"0"`

	AuthorityName string `json:"authority_name"  binding:"required"`

	Type *int `json:"type" binding:"required"`
}

type AuthorityUpdateRequest struct {
	AuthorityId int64 `json:"authority_id" binding:"required"`

	AuthorityName string `json:"authority_name"  binding:"required"`

	Type *int `json:"type" binding:"required"`

	ParentId int64 `json:"parent_id"`

	CreatedAt int64 `json:"created_at"`
}

type AuthorityListRequest struct {
	Index int `json:"index"`
	Size  int `json:"size"`

	AuthorityId int64 `json:"authority_id"`

	ParentId int64 `json:"parent_id"`
}

type AuthorityListResponse struct {
	Total int              `json:"total"`
	Data  []*AuthorityInfo `json:"list"`
}

type AuthorityInfo struct {
	AuthorityId int64 `json:"authority_id"`

	AuthorityName string `json:"authority_name"`

	ParentId int64 `json:"parent_id"`

	DefaultRouter string `json:"default_router"`

	Type int `json:"type"`

	CreatedAt int64 `json:"created_at"`

	UpdatedAt int64 `json:"updated_at"`
}

type AuthorityDeleteRequest struct {
	AuthorityId int64 `json:"authority_id"`
}

func AuthoritysEntityToDto(authoritys []*entity.Authority) []*AuthorityInfo {
	out := make([]*AuthorityInfo, 0, len(authoritys))
	for _, c := range authoritys {
		out = append(out, AuthorityEntityToDto(c))
	}
	return out
}

func AuthorityEntityToDto(e *entity.Authority) *AuthorityInfo {
	return &AuthorityInfo{

		AuthorityId: e.AuthorityId,

		AuthorityName: e.AuthorityName,

		ParentId: e.ParentId,

		DefaultRouter: e.DefaultRouter,

		Type: e.Type,

		CreatedAt: e.CreatedAt,

		UpdatedAt: e.UpdatedAt,
	}
}
